<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>JS创建文件并请求下载到本地</title>
</head>
<body>
    <a href="http://www.baidu.com" download="baidu">百度</a>
</body>
<script>
    let data = "aaaaaaaaa"
    let blob = new Blob([data],{
        type:"image/png"
    })
    let a = document.createElement('a')
    a.download = "test"
    a.href = URL.createObjectURL(blob)
    a.click()
</script>
</html>